/* eslint-disable no-use-before-define */
import axios, { type Paging, type Response } from '@/utils/axios/axios';

/** 得到申请列表 */
export function getApplyCooperationUserListAxios(data: GetApplyCooperationUserListRequest): Promise<Response<Paging<ApplyCooperationUser>>> {
  const _data: GetApplyCooperationUserListRequest = JSON.parse(JSON.stringify(data));
  if (![0, 1, 2].includes(data.status ?? -1)) {
    delete _data.status;
  }
  return axios.get(`/system/partnerApply/page`, { params: _data }) as unknown as Promise<Response<Paging<ApplyCooperationUser>>>;
}

/** 合作方审核 */
export function auditCooperationUserAxios(data: AuditCooperationUserRequest): Promise<Response<string>> {
  if (data.status === 1) {
    data.remark = '';
  }
  return axios.post(`/system/partnerApply/verify`, data) as unknown as Promise<Response<string>>;
}

/** 删除申请 */
export function delApplyCooperationUserAxios(applyId: number): Promise<Response<string>> {
  return axios.delete(`/system/partnerApply/remove`, { params: { applyId } }) as unknown as Promise<Response<string>>;
}

/** 得到合作剧集表 */
export function getCooperationDramaListAxios(data: GetCooperationDramaListRequest): Promise<Response<Paging<CooperationDrama>>> {
  return axios.get(`/system/dramaIncome/getPage`, { params: data }) as unknown as Promise<Response<Paging<CooperationDrama>>>;
}

/** 设置合作剧集信息（比例，人数，显示金额） */
export function settingCooperationInfoAxios(data: SettingCooperationInfoRequest): Promise<Response<Paging<string>>> {
  const _data: SettingCooperationInfoRequest = JSON.parse(JSON.stringify(data));
  _data.thatDayLimitRate = typeof _data.thatDayLimitRate === 'number' ? _data.thatDayLimitRate / 100 : null;
  return axios.post(`/system/dramaIncome/updateSetingParamas`, _data) as unknown as Promise<Response<Paging<string>>>;
}

/** 设置全局默认信息 */
export function settingCooperationDefaultAxios(data: GlobalDefault): Promise<Response<Paging<string>>> {
  const _data: GlobalDefault = JSON.parse(JSON.stringify(data));
  _data.thatDayLimitRate = typeof _data.thatDayLimitRate === 'number' ? _data.thatDayLimitRate / 100 : 0.8;
  return axios.post(`/system/dict/updateDictParam`, _data) as unknown as Promise<Response<Paging<string>>>;
}

/** 得到全局默认信息 */
export function getCooperationDefaultAxios(): Promise<Response<GlobalDefault>> {
  return axios.get(`/system/dict/getDictIncomeValue`) as unknown as Promise<Response<GlobalDefault>>;
}

export type GlobalDefault = {
  /** 显示昨日数据时间  */
  showRecordTime: string;
  /** 当日金额限定比例  */
  thatDayLimitRate: number;
};

export type SettingCooperationInfoRequest = {
  /** id */
  incomeId: number | null;
  /** 设定的当日收入金额 */
  virtualThatDayAmount: number | null;
  /** 昨日收入金额限定比例 */
  thatDayLimitRate: number | null;
};

export type GetCooperationDramaListRequest = {
  /** 当前页 */
  current: number;
  /** 每页数量 */
  size: number;
  /** 短剧名称 */
  dramaTitle: string;
  /** 合作方用户账号 */
  username: string;
};

export type GetApplyCooperationUserListRequest = {
  /** 当前页 */
  current: number;
  /** 每页数量 */
  size: number;
  /** 审核状态：0-待审核；1-通过；2-驳回； */
  status?: -1 | 0 | 1 | 2;
  /** 联系电话 */
  phone?: string;
};

export type ApplyCooperationUser = {
  /** 申请主键ID  */
  applyId: number;
  /** 申请理由 */
  applyReason: string | null;
  /** 昵称 */
  nickname: string;
  /** 联系电话 */
  phone: string;
  /** 原因 */
  remark: string | null;
  /** 审核状态：0-待审核；1-通过；2-驳回； */
  status: 0 | 1 | 2;
  /** app用户ID */
  userId: number;
  /** 登录账号 */
  username: string;
};

export type AuditCooperationUserRequest = {
  /** 申请 ID */
  applyId?: number;
  /** 状态 0:待审核 1:同意 2:驳回 */
  status?: 0 | 1 | 2;
  /** 备注 */
  remark: string;
};

export type CooperationDrama = {
  /** 全集购买次数  */
  allEpisodePayNum: number;
  /** 全集收入总金额 */
  allEpisodeTotalAmount: number;
  /** 日期时间戳（yyyy-MM-dd格式的时间戳，秒）  */
  dateTimeStamp: number;
  /** 短剧id */
  dramaId: number;
  /** 短剧名称 */
  dramaTitle: string;
  /** 收入统计ID */
  incomeId: number;
  /** 收入总金额 * 昨日收入金额限定比例  */
  limitTotalAmount: number;
  /** 昵称 */
  nickname: string;
  /** 单集购买次数  */
  singleEpisodePayNum: number;
  /** 单集收入总金额  */
  singleEpisodeTotalAmount: number;
  /** 昨日收入金额 */
  thatDayAmount: number;
  /** 收入总金额  */
  totalAmount: number;
  /** 登录账号  */
  username: string;
  /** 设定的当日收入金额 */
  virtualThatDayAmount: number | null;
  /** 昨日支付次数限制 */
  thatDayLimitPayNum: number | null;
  /** 昨日收入金额限定比例 */
  thatDayLimitRate: number | null;
};
